// $Id: tcp.h 84 2011-04-24 09:23:49Z cedric.shih@gmail.com $
/*
 * Copyright (C) 2011 Cedric Shih <cedric.shih@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef TCP_H_
#define TCP_H_

#include <sys/time.h>

#include <nio/tcp.h>

struct niotcp_handler {
	struct niofuture *future;
	struct timeval tv;
	struct timeval *timeout;
	const char *name;
	struct niochannel *channel;
	struct niobuffer *upstream;
	struct niobuffer *downstream;
};

int niotcp_handler_setup(void *obj, const char *name);

int niotcp_handler_teardown(void *obj);

int niotcp_handler_handle_upstream(void *obj,
		struct niochannel *channel, void *message);

int niotcp_handler_handle_downstream(void *obj,
		struct niochannel *channel, void *message);

int niotcp_handler_read(struct niotcp_handler *handler);

int niotcp_handler_write(struct niotcp_handler *handler);

void niotcp_handler_on_readable(struct niofuture *future,
		struct niosocket *socket, int flags, void *cbarg);

void niotcp_handler_on_writable(struct niofuture *future,
		struct niosocket *socket, int flags, void *cbarg);

#endif /* TCP_H_ */
